Professional Documents
Culture Documents
Table of Contents
Introduction
Themes
Configuration
Templates
Conclusion
Introduction
Liferay has recently released version 3.5 of Liferay Portal. One major benefit of the new
release is that new features and key enhancements make it possible for you to seamlessly
integrate your website and portal, either by giving your portal the same look and feel as
In this tutorial, we will explain Liferay Portal 3.5’s new "Themes” feature in detail. Then we
will discuss how to use Themes in conjunction with other new features to easily build your
Themes
Themes make it possible to easily switch among different presentational or "look and feel"
layers. Within a single .war file, a designer/developer can deliver an integrated package of
JSP (or Velocity), Javascript, image and configuration files that will control all presentation
logic and design attributes for a portal community. Liferay Portal 3.5 comes with a handful
of pre-made themes that showcase the versatility and creative possibilities themes enable:
Themes in Liferay Portal 3.5 are also incredibly flexible in how they can be applied:
Users can choose a unique theme for their own personal portal page
Both Java Server Page (JSP) and Velocity (VM) languages are supported
To select a different theme, simply go to the Look and Feel section (in the header bar) and
choose one of the available themes and a corresponding color scheme. The process is as
creativity to work and design your own. Making a new theme requires only four main
steps:
1. Configure properties
2. Edit templates (JSP or VM)
3. Define CSS styles
4. Code JavaScript (optional)
Let’s take a high-level look at how Liferay created the JSP-based "Brochure" theme (Figure
2.6) by modifying a few things in a copy of the "Classic" theme (Figure 2.1).
Note: If you want to see an example using VM, take a look at the bundled "Velocity" theme
(Figure 2.3).
Configuration
To start, we created a copy of the "Classic" theme’s directory and renamed it "brochure."
would only have one color scheme for the "Brochure" theme. Although you don’t have to
follow the layout shown here, this convention will make your themes easier to organize
Once we have a directory to house our new theme, we need to let Liferay know the new
theme’s directory location. This is done in liferay-look-and-feel.xml (Figure
2.1.1.2). Notice that the theme configuration shows theme id="brochure" and identifies
the compatible version. The root-path, templates-path and images-path are also set here.
<look-and-feel>
<compatibility>
<version>3.5.0</version>
</compatibility>
<theme id="brochure" name="Brochure">
<root-path>/html/themes/brochure</root-path>
<templates-path>/html/themes/brochure/templates</templates-path>
<images-path>/html/themes/brochure/images</images-path>
<template-extension>jsp</template-extension>
<color-scheme id="01" name="Default">
<!-- color-scheme content omitted to simplify example -->
</color-scheme>
</theme>
</look-and-feel>
Figure 2.1.1.2 liferay-look-and-feel.xml
Templates
Now that Liferay Portal is configured to load your theme, the next step is to edit the
template files that give the theme its uniqueness. Here’s a brief description of some of the
Each template controls the layout of a particular area within the portal. For instance,
portlet_top.jsp controls the top portion of each portlet; navigation.jsp determines
how the navigation bar will look.
Keep in mind that not all of these templates require modification; nor are you limited to
the ones mentioned here. Feel free to add another template to control a different area of
the portal. Just make sure to include the template in portal_normal.jsp and/or
portal_pop_up.jsp.
A number of changes were made to these templates for the brochure theme. Highlighted,
you can see one such major change made to the placement and appearance of the portal
tabs.
Figure 2.1.2.2 The "Brochure" theme's portal config menu is relocated to the top
of the portal.
In the "Classic" theme, the portal configuration menu is part of the navigation bar. It
consists of buttons and a dropdown menu. By contrast, the "Brochure" theme has the
portal configuration menu relocated to the top of the portal and separated from the
navigation bar. Also notice that the buttons are now simple text links. Some of the code
<div id="layout-outer-side-decoration">
<div id="layout-inner-side-decoration">
<div id="layout-top-decoration">
<div id="layout-corner-ul"></div>
<div id="layout-corner-ur"></div>
</div>
<div id="layout-box">
<div id="layout-top">
<div id="layout-logo">
<a class="bg" href="<%= themeDisplay.getPathFriendlyURL()
%>/guest/home"><img border="0" hspace="0" src="<%=
themeDisplay.getCompanyLogo() %>" vspace="0"></a>
</div>
<c:if test="<%=
GetterUtil.getBoolean(PropsUtil.get(PropsUtil.UNIVERSAL_PERSONALIZATI
ON)) || RoleLocalServiceUtil.isPowerUser(user.getUserId()) %>">
<a style="font-size: 8pt" href="<%= themeDisplay.getPathMain()
%>/portal/personalize_forward?group_id=<%= portletGroupId %>"><%=
LanguageUtil.get(pageContext, "content-and-layout") %></a> -
</c:if>
<c:if test="<%=
GetterUtil.getBoolean(PropsUtil.get(PropsUtil.LOOK_AND_FEEL_MODIFIABL
E)) %>">
<a style="font-size: 8pt" href="<%= themeDisplay.getPathMain()
%>/portal/look_and_feel_forward?group_id=<%= portletGroupId %>"><%=
LanguageUtil.get(pageContext, "look-and-feel") %></a> -
</c:if>
<font size="2">
<select name="my_communities_sel" style="font-family: Verdana, Arial;
font-size: smaller; font-weight: normal;" onChange="self.location =
'<%= themeDisplay.getPathMain() %>/portal/group_forward?group_id=' +
this.value;">
<option <%= !layout.isGroup() ? selectedStyle : "" %> value="<%=
Group.DEFAULT_PARENT_GROUP_ID %>"><%= LanguageUtil.get(pageContext,
"desktop") %></option>
<% } %>
</select>
</font>
</div>
</c:if>
Figure 2.1.2.3 top.jsp for the "Brochure" theme
CSS Styles
Another major part of every theme is the collection of presentation attributes such as font
size, background color, padding and margin. The best way to control these attribute in
your theme is to use cascading style sheets (CSS). As mentioned briefly above, css.jsp
contains all the CSS style definitions for your theme. Liferay Portal’s default themes include
all JSR-168 standard style definitions. You may also add theme-specific style definitions to
css.jsp. Using the templates and adding custom images as necessary, you can use
standard and custom style definitions to give your theme a distinctive look and feel. Let’s
Header Bar
.portlet-header-bar {
background-color: #e0e0e0;
margin: 0 1px 0 1px;
padding: 3px 0px 3px 0px;
position: relative;
z-index: 2;
}
portlet_top template is used to draw the top of each portlet within the portal. As you
can see from the portlet-header-bar definition, the header bar for each portlet should
have a gray background color, with a small margin on its sides, padding on top and
sheet is a JSP file, you can use JSP tags to dynamically assign some of your style definition
.portlet-title {
color: <%= colorScheme.getPortletTitleText() %>
font-family: Tahoma, Arial;
font-size: smaller;
vertical-align: middle;
}
In the above code, portlet-title’s color attribute has its value retrieved dynamically.
This way, depending on the color scheme selected on the "Look and Feel" page in the
portal, the title bar will have a color appropriate to the currently selected color scheme.
Please refer to the theme user guide for more information.
JavaScript
Lastly, you are free to use JavaScript to create a more dynamic interface for your theme.
To use a script, all you have to do is put the script file inside your theme directory, then
provide the location of this file in the script declaration in javascript.jsp. For example,
hard-coding information in your templates. Refer to the API to see other variables and
Both the "Clean" theme (Figure 2.5) and the "Genesis" theme (Figure 2.4) use JavaScript
to create a dynamic interface.
straightforward to combine static CMS articles and functionality-rich portlets on the same
portal page. One direct application of this capability would be to create your public website
using Liferay, and thereby enable the inclusion of portlets on your website. Not only would
you be able to reuse functional components and find innovative ways to use them, but you
could also quickly build new pages out of common components within a tightly-managed
CMS framework.
As an example, suppose an insurance company wants to show their customers how much
they can save by switching to their insurance plan. Online visitors can go to their website,
fill out a short form, and receive pricing information instantaneously. If this insurance
company uses Liferay 3.5 to build their website, they can easily develop a pricing
calculator portlet, grant guest access, and display it on the front page of their website. The
CMS-managed article describing the plan can be placed right beside the calculator portlet.
Also, incorporating portlets into your website helps to encourage reuse. If two different
pages on your website need to offer the same functionality, one portlet can simply be
Liferay Portal 3.5 also comes with portlets specifically designed to help you build a public
website easily. The Breadcrumb Portlet keeps track of how deep a user has gone into the
navigation of a site. The Navigation Portlet can be configured to act as a standard nested
navigation menu. These and other portlets can be re-used and easily included on every
content page where they are needed, and once the main Theme layout has been created,
psges can be put together using these portlets without touching the presentation code.
Besides providing functionality, a website also needs to provide information. Liferay Portal
3.5 allows CMS articles to be inserted into your portal just like any other portlet. You can
Taking the above example, the insurance company may want one portlet containing a CMS
article describing their pricing. Right next to it is another portlet with a CMS articles haring
customer testimonials. The layout of the page the articles live in is managed within the
portal’s admin section, and the content and layout of the individual articles is easily
Liferay Portal 3.5 also ships with the Runtime Portlet and the Portlet Aggregator. The
Runtime Portlet is used to embed portlets into CMS articles. This portlet is used at
Liferay.com to embed an instance of the Login Portlet within the article that’s displayed on
The Portlet Aggregator provides a flexible means to lay out several portlets. You are no
longer confined to the strict rigidity of a column layout, but can rather set the layout of
In Liferay’s next Javalobby article, we’ll explore both of these portlets in greater detail.
Note: For documentation on Liferay’s CMS, please see the CMS User Guide.
pages (which showcased version 3.2 capabilities). In this new paradigm, each page on the
website is a layout (page) comprised of several different portlets. To illustrate, let’s take
Liferay’s "Company Overview" page as an example. Figure 2.1.4.1 shows the webpage
with each of the five portlets marked. (You can view the actual page here.)
Figure 2.1.4.1 Company Overview
Company Overview, like most other pages on Liferay.com, is a portal layout (page) with
two columns, one narrow and one wide, containing various portlets that supply its content.
Portlets two and four, denoted in Figure 2.1.4.1, are instances of the Navigation and
Breadcrumb Portlets, respectively. The remaining three portlets are instances of the
Journal Content portlet; each contains its own CMS article. Portlet one and three contain a
single picture each, and portlet five contains a detailed overview of Liferay.
You can add, delete, and organize page layouts by using the Admin section (Figure
For the Company page, we added the "Company" layout right under the "Home" layout.
Also notice the Friendly URL field. This field allows you to assign a simple URL to a layout.
www.liferay.com/web/guest/company.
Once the "Company" page layout has been added, you can add different portlets to it to
Note: When assembling your webpage, remember to extract all the presentation attributes
to your theme. This way, all the attributes are centralized. For example, to remove the gap
between the wide and narrow columns, we set the "margin" attribute in the "Brochure"
theme to zero.
Conclusion
Liferay 3.5 provides a lot of flexibility and control to customize the overall user experience
of your portal or website. The availability of a number of different ways to manage, use
and display CMS content and portlets begets limitless possibilities for innovation using
Liferay Portal.
To see Liferay Portal 3.5 in action, visit demo.liferay.net and create a user account for
yourself. You can also explore Liferay.com to get a sense of how the portal was used to
build that site and begin to imagine the possibilities for your own website or portal.